package com.jiangjiang.eshop.schedule.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.schedule.convert.ScheduleGoodsAllocationStockDetailConvert;
import com.jiangjiang.eshop.schedule.dao.ScheduleGoodsAllocationStockDetailMapper;
import com.jiangjiang.eshop.schedule.domain.ScheduleGoodsAllocationStockDetail;
import com.jiangjiang.eshop.wms.dto.GoodsAllocationStockDetailDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @ClassName ScheduleGoodsAllocationStockDetailService
 * @Description 货位库存明细service
 * @Author jhw
 * @Date 2021/7/24 16:05
 * @Version 1.0
 **/
@Service
public class ScheduleGoodsAllocationStockDetailService extends ServiceImpl<ScheduleGoodsAllocationStockDetailMapper, ScheduleGoodsAllocationStockDetail> {

    @Autowired
    private ScheduleGoodsAllocationStockDetailConvert scheduleGoodsAllocationStockDetailConvert;

    /**
     * 根据goodsSkuId 查询货位库存明细数据
     * @param goodsId
     * @return
     */
    public List<ScheduleGoodsAllocationStockDetail> listByGoodsSkuId(Long goodsId) {
        LambdaQueryWrapper<ScheduleGoodsAllocationStockDetail> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ScheduleGoodsAllocationStockDetail::getGoodsSkuId, goodsId)
                .orderByAsc(ScheduleGoodsAllocationStockDetail::getPutOnTime);
        return this.list(wrapper);
    }

    /**
     * 批量保存货位库存明细数据
     * @param stockDetails 货位库存明细数据
     */
    public void saveBatchDetailDTO(List<GoodsAllocationStockDetailDTO> stockDetails) {
        this.saveBatch(scheduleGoodsAllocationStockDetailConvert.convertDTO2Entities(stockDetails));
    }

    /**
     * 根据id 集合批量查询货位库存明细数据
     * @param detailIds id集合数据
     * @return 查询结果
     */
    public List<ScheduleGoodsAllocationStockDetail> queryByIds(Set<Long> detailIds) {
        LambdaQueryWrapper<ScheduleGoodsAllocationStockDetail> wrapper = Wrappers.lambdaQuery();
        wrapper.in(ScheduleGoodsAllocationStockDetail::getId, detailIds);
        return this.list(wrapper);
    }
}
